package main

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
)

func main() {
	// Directory to search
	dir := "pkg"

	// Walk through all files
	err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		// Skip directories
		if info.IsDir() {
			return nil
		}

		// Only process Go files
		if !strings.HasSuffix(path, ".go") {
			return nil
		}

		// Read file
		data, err := ioutil.ReadFile(path)
		if err != nil {
			return err
		}

		// Replace import paths
		content := string(data)
		if strings.Contains(content, "github.com/AsynkronIT/protoactor-go") {
			fmt.Printf("Fixing imports in %s\n", path)
			content = strings.ReplaceAll(content, "github.com/AsynkronIT/protoactor-go", "github.com/asynkron/protoactor-go")

			// Write file
			err = ioutil.WriteFile(path, []byte(content), info.Mode())
			if err != nil {
				return err
			}
		}

		return nil
	})

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		os.Exit(1)
	}

	fmt.Println("Done!")
}
